package home.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONObject;

import home.model.Msg;
import home.model.Users;
import home.service.MsgService;

import com.opensymphony.xwork2.ActionSupport;

public class MsgAction extends ActionSupport{
	private MsgService msgs;
	private String type;
	private List<Msg> msgListAdv;
	private List<Msg> msgListNews;
	private List<Msg> msgListBc;
	private int id;
	private String result;
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getType() {
		return type;
	}

	public List<Msg> getMsgListAdv() {
		return msgListAdv;
	}

	public void setMsgListAdv(List<Msg> msgListAdv) {
		this.msgListAdv = msgListAdv;
	}

	public List<Msg> getMsgListNews() {
		return msgListNews;
	}

	public void setMsgListNews(List<Msg> msgListNews) {
		this.msgListNews = msgListNews;
	}

	public List<Msg> getMsgListBc() {
		return msgListBc;
	}

	public void setMsgListBc(List<Msg> msgListBc) {
		this.msgListBc = msgListBc;
	}

	public void setType(String type) {
		this.type = type;
	}

	public MsgService getMsgs() {
		return msgs;
	}

	public void setMsgs(MsgService msgs) {
		this.msgs = msgs;
	}
	
	public String execute() throws Exception{
		msgListAdv = msgs.getAllMsgHome("adv");
		msgListNews = msgs.getAllMsgHome("news");
		msgListBc = msgs.getAllMsgHome("bc");
		return SUCCESS;
	}
	
	public String addReadnum() throws Exception{
	    HttpServletResponse response = ServletActionContext.getResponse();
	    PrintWriter out  = response.getWriter();
	    msgs.addReadnum(id);
	    
	    JSONObject jsonO = new JSONObject();
	    jsonO.put("result",true);
		out.print(jsonO);
		out.flush();
		out.close();
		return SUCCESS;
	}
}
